﻿Public Class ObraSocialXPlanDAO

    Public Shared Function insertarObraSocialXPlan(ByVal ObraSocialId As Integer, ByVal PlanId As Integer, ByVal ObraSocialXPlanLlevaDetalle As Boolean) As Boolean
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim consulta As New SqlClient.SqlCommand
            With consulta
                .CommandText = "usp_ObraSocialXPlan"
                .CommandType = CommandType.StoredProcedure
                With .Parameters
                    .AddWithValue("@Accion", Constante.INSERTAR).DbType = DbType.Int32
                    .AddWithValue("@ObraSocialXPlanId", Constante.MENOSUNO).DbType = DbType.Int32
                    .AddWithValue("@ObraSocialId", ObraSocialId).DbType = DbType.Int32
                    .AddWithValue("@PlanId", PlanId).DbType = DbType.Int32
                    .AddWithValue("@ObraSocialXPlanLlevaDetalle", ObraSocialXPlanLlevaDetalle).DbType = DbType.Boolean
                End With
                .Connection = cn
                .ExecuteNonQuery()
            End With
            Return True
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return False
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function obtenerObrasSocialesXPlanes(ByVal ObraSocialXPlanId As Integer) As DataTable
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim ds As New DataSet
            Dim da As New SqlClient.SqlDataAdapter("usp_obraSocialXPlan_obtener", cn)
            da.SelectCommand.CommandType = CommandType.StoredProcedure
            da.SelectCommand.Parameters.AddWithValue("@ObraSocialXPlanId", ObraSocialXPlanId).DbType = DbType.Int32
            da.Fill(ds, "ObrasSocialesXPlanes")

            Return ds.Tables("ObrasSocialesXPlanes")
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return Nothing
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function actualizarObraSocialXPlan(ByVal ObraSocialXPlanId As Integer, ByVal ObraSocialId As Integer, ByVal PlanId As Integer, ByVal ObraSocialXPlanLlevaDetalle As Boolean) As Boolean
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim consulta As New SqlClient.SqlCommand
            With consulta
                .CommandText = "usp_ObraSocialXPlan"
                .CommandType = CommandType.StoredProcedure
                With .Parameters
                    .AddWithValue("@Accion", Constante.ACTUALIZAR).DbType = DbType.Int32
                    .AddWithValue("@ObraSocialXPlanId", ObraSocialXPlanId).DbType = DbType.Int32
                    .AddWithValue("@ObraSocialId", ObraSocialId).DbType = DbType.Int32
                    .AddWithValue("@PlanId", PlanId).DbType = DbType.Int32
                    .AddWithValue("@ObraSocialXPlanLlevaDetalle", ObraSocialXPlanLlevaDetalle).DbType = DbType.Boolean
                End With
                .Connection = cn
                .ExecuteNonQuery()

            End With
            Return True
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return False
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function eliminarObraSocialXPlan(ByVal ObraSocialXPlanId As Integer) As Boolean
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim consulta As New SqlClient.SqlCommand
            With consulta
                .CommandText = "usp_ObraSocialXPlan"
                .CommandType = CommandType.StoredProcedure
                With .Parameters
                    .AddWithValue("@Accion", Constante.ELIMINAR).DbType = DbType.Int32
                    .AddWithValue("@ObraSocialXPlanId", ObraSocialXPlanId).DbType = DbType.Int32
                    .AddWithValue("@ObraSocialId", Constante.MENOSUNO).DbType = DbType.Int32
                    .AddWithValue("@PlanId", Constante.MENOSUNO).DbType = DbType.Int32
                    .AddWithValue("@ObraSocialXPlanId", False).DbType = DbType.Boolean
                End With
                .Connection = cn
                .ExecuteNonQuery()
            End With

            Return True
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return False
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function comboObraSocialXPlan() As DataTable
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim ds As New DataSet
            Dim da As New SqlClient.SqlDataAdapter("usp_ObraSocialXPlan_combo", cn)
            da.SelectCommand.CommandType = CommandType.StoredProcedure
            da.SelectCommand.Connection = cn
            da.Fill(ds, "ObrasSocialesXPlanes")

            Return ds.Tables("ObrasSocialesXPlanes")

        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return Nothing
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function comboObraSocialXPlan_obtenerXId(ByVal ObraSocialXPlanId As Integer) As DataTable
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim ds As New DataSet
            Dim da As New SqlClient.SqlDataAdapter("usp_comboObraSocialXPlan_obtenerXId", cn)
            da.SelectCommand.CommandType = CommandType.StoredProcedure
            da.SelectCommand.Connection = cn
            With da.SelectCommand.Parameters
                .AddWithValue("@ObraSocialXPlanId", ObraSocialXPlanId).DbType = DbType.Int32
            End With
            da.Fill(ds, "ObrasSocialesXPlanes")

            Return ds.Tables("ObrasSocialesXPlanes")

        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return Nothing
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function comboFiltroObraSocialXPlan() As DataTable
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim ds As New DataSet
            Dim da As New SqlClient.SqlDataAdapter("usp_ObraSocialXPlan_comboFiltro", cn)
            da.SelectCommand.CommandType = CommandType.StoredProcedure
            da.SelectCommand.Connection = cn
            da.Fill(ds, "ObrasSocialesXPlanes")

            Return ds.Tables("ObrasSocialesXPlanes")

        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return Nothing
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

End Class
